package com.yc.mapper;

import com.yc.entity.Promotion;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.entity.Promotiondetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author cxw
 * @since 2025-02-13
 */
public interface PromotionMapper extends BaseMapper<Promotion> {
        @Select("select*from promotion where status=0 order by begin limit 0,1")
        @Results(
                id ="rm1",
                value={
                        @Result(column = "id", property="id",id=true),
                        @Result(column = "id",property = "details",many = @Many(select = "selectByPid")),

                }
        )
        Promotion selectNoBegin();
        @Select("select *from promotiondetail where pid=#{pid}")
        @Results(
                id ="rm2",
                value={
                        @Result(column = "id", property="id",id=true),
                        @Result(column = "gid",property = "mgoods",one = @One(select = "package com.yc.mapper.MgoodsMapper.selectById")),

                }
        )
        List<Promotiondetail> selectByPid(int pid);

        @Select("select *from promotion where pid=#{pid}")
        @ResultMap("rm1")
        Promotion queryById(int pid);
}
